package controllers.jobs;

import play.Logger;
import play.Play;
import play.jobs.Job;
import play.jobs.OnApplicationStart;
import play.vfs.VirtualFile;

import java.io.IOException;
import java.util.Properties;

/**
 * Created by xuyang on 2017/6/15.
 */
@OnApplicationStart
public class BootstrapJob extends Job {
    @Override
    public void doJob() throws Exception {
        Logger.info("BootstrapJob start");

        loadVersion();
    }

    private void loadVersion() {

        final String filepath = "conf/version";

        VirtualFile versionFile = Play.getVirtualFile(filepath);

        Logger.debug(versionFile.getRealFile().getAbsolutePath());

        try {
            Play.configuration.load(versionFile.inputstream());
        } catch (IOException e) {
            Logger.debug("Version file open failed: " + e.getLocalizedMessage());
            return;
        }

        Logger.info("App version: " + Play.configuration.getProperty("build.version"));
    }
}
